<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>门店管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" media="all">
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">搜索</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="请输入门店名称/地址/电话" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-store-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>

                <!-- <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-list" data-type="add">添加门店</button>
                </div> -->

                <table id="LAY-store-list" lay-filter="LAY-store-list"></table>
            </div>
        </div>
    </div>

    <script type="text/html" id="table-store-status">
        {{#  if(d.status === 1){ }}
            <span class="layui-badge layui-bg-green">启用</span>
        {{#  } else { }}
            <span class="layui-badge">禁用</span>
        {{#  } }}
    </script>

    <script type="text/html" id="table-store-operation">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a> -->
    </script>

    <script src="/app/admin/component/layui/layui.js"></script>
    <script src="/app/admin/component/pear/pear.js"></script>
    <script>
    layui.use(['table', 'form', 'layer'], function(){
        var $ = layui.$
        ,table = layui.table
        ,form = layui.form
        ,layer = layui.layer;
        
        //门店列表
        table.render({
            elem: '#LAY-store-list'
            ,url: '/app/ky_shouyin/admin/store/list'
            ,cols: [[
                {field: 'id', title: 'ID', width: 80, sort: true}
                ,{field: 'name', title: '门店名称', width: 150}
                ,{field: 'address', title: '门店地址', width: 200}
                ,{field: 'phone', title: '联系电话', width: 120}
                ,{field: 'business_hours', title: '营业时间', width: 120}
                ,{field: 'manager_name', title: '负责人', width: 100}
                ,{field: 'manager_phone', title: '负责人电话', width: 120}
                ,{field: 'status', title: '状态', width: 100, templet: '#table-store-status'}
                ,{field: 'remark', title: '备注'}
                ,{field: 'created_at', title: '创建时间', width: 160}
                ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-store-operation'}
            ]]
            ,page: true
            ,limit: 15
            ,text: {
                none: '暂无数据'
            }
        });
        
        //监听搜索
        form.on('submit(LAY-store-search)', function(data){
            var field = data.field;
            
            //执行重载
            table.reload('LAY-store-list', {
                where: field
            });
        });
        
        //监听工具条
        table.on('tool(LAY-store-list)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑门店'
                    ,content: '/app/ky_shouyin/admin/store/edit?id=' + data.id
                    ,area: ['800px', '600px']
                    // ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find('#LAY-store-edit-submit');
                        submit.click();
                    }
                });
            } else if(obj.event === 'del'){
                layer.confirm('确定删除该门店？', function(index){
                    $.ajax({
                        url: '/app/ky_shouyin/admin/store/delete'
                        ,type: 'POST'
                        ,data: {id: data.id}
                        ,success: function(res){
                            if(res.code === 0){
                                layer.msg('删除成功', {icon: 1});
                                obj.del();
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
        
        var active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加门店'
                    ,content: '/app/ky_shouyin/admin/store/add'
                    ,area: ['800px', '600px']
                    ,maxmin: true
                });
            }
        };
        
        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    </script>
</body>
</html> 